<?xml version="1.0" encoding="UTF-8"?>

<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<!--
    POM file.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.apache.ignite</groupId>
        <artifactId>ignite-parent</artifactId>
        <version>${revision}</version>
        <relativePath>parent/pom.xml</relativePath>
    </parent>

    <artifactId>apache-ignite</artifactId>
    <packaging>pom</packaging>

    <modules>
        <module>modules/checkstyle</module>
        <module>parent</module>
        <module>parent-internal</module>
        <module>modules/bom</module>
        <module>modules/tools</module>
        <module>modules/core</module>
        <module>modules/compress</module>
        <module>modules/dev-utils</module>
        <module>modules/direct-io</module>
        <module>modules/extdata/p2p</module>
        <module>modules/extdata/uri</module>
        <module>modules/extdata/platform</module>
        <module>modules/extdata/pluggable</module>
        <module>modules/clients</module>
        <module>modules/spring</module>
        <module>modules/web</module>
        <module>modules/urideploy</module>
        <module>modules/indexing</module>
        <module>modules/rest-http</module>
        <module>modules/jta</module>
        <module>modules/log4j2</module>
        <module>modules/slf4j</module>
        <module>modules/jcl</module>
        <module>modules/codegen</module>
        <module>modules/zookeeper</module>
        <module>modules/web/ignite-appserver-test</module>
        <module>modules/web/ignite-websphere-test</module>
        <module>modules/kubernetes</module>
        <module>modules/sqlline</module>
        <module>modules/opencensus</module>
        <module>modules/control-utility</module>
        <module>modules/calcite</module>
    </modules>

    <profiles>
        <profile>
            <id>all-java</id> <!-- used to update project versions and check all modules compilation -->
            <modules> <!-- sorted alphabetically -->
                <module>examples</module>
                <module>modules/benchmarks</module>
                <module>modules/compatibility</module>
                <module>modules/ducktests</module>
                <module>modules/numa-allocator</module>
                <module>modules/schedule</module>
                <module>modules/yardstick</module>
            </modules>
        </profile>

        <profile>
            <id>all-other</id> <!-- used to update project versions and check all modules compilation -->
            <modules> <!-- sorted alphabetically -->
            </modules>
        </profile>

        <profile>
            <id>ducktests</id>
            <modules>
                <module>modules/ducktests</module>
            </modules>
        </profile>

        <profile>
            <id>numa-allocator</id>
            <modules>
                <module>modules/numa-allocator</module>
            </modules>
        </profile>

        <profile>
            <id>compatibility</id>
            <modules>
                <module>modules/compatibility</module>
            </modules>
        </profile>

        <profile>
            <id>build-dotnet</id>
            <modules>
                <module>modules/platforms/dotnet</module>
            </modules>
        </profile>

        <profile>
            <id>javadoc</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <version>3.0.0</version>
                        <executions>
                            <execution>
                                <id>timestamp-property</id>
                                <goals>
                                    <goal>timestamp-property</goal>
                                </goals>
                                <phase>validate</phase>
                                <configuration>
                                    <name>current.year</name>
                                    <pattern>yyyy</pattern>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>core-javadoc</id>
                                <goals>
                                    <goal>aggregate-no-fork</goal>
                                </goals>
                                <phase>validate</phase>
                                <configuration>
                                    <!--
                                    For some reason maven-javadoc-plugin 3.0+ doesn't include taglet artifact from
                                    parent configuration to -tagletpath javadoc parameter.
                                    -->
                                    <tagletArtifact>
                                        <groupId>${project.groupId}</groupId>
                                        <artifactId>ignite-tools</artifactId>
                                        <version>${project.version}</version>
                                    </tagletArtifact>
                                    <reportOutputDirectory>${basedir}/target/javadoc</reportOutputDirectory>
                                    <destDir>core</destDir>
                                    <subpackages>org.apache.ignite -exclude org.apache.ignite.codegen:org.apache.ignite.examples:org.apache.ignite.internal:org.apache.ignite.schema:org.apache.ignite.tests:org.apache.ignite.tools:org.apache.ignite.util:org.apache.ignite.spi.discovery.tcp.messages:org.apache.ignite.spi.discovery.tcp.internal:org.apache.ignite.spi.communication.tcp.internal:org.apache.ignite.spi.discovery.zk.internal:org.apache.ignite.spi.deployment.uri.scanners:org.apache.ignite.spi.deployment.uri.tasks:org.apache.ignite.yardstick:org.apache.ignite.webtest</subpackages>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <inherited>false</inherited>
                        <dependencies>
                            <dependency>
                                <groupId>${project.groupId}</groupId>
                                <artifactId>ignite-tools</artifactId>
                                <version>${project.version}</version>
                            </dependency>
                        </dependencies>
                        <executions>
                            <execution>
                                <id>javadoc-postprocessing-new</id>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <phase>initialize</phase>
                                <configuration>
                                    <target>
                                        <copy todir="${basedir}/target/javadoc/core">
                                            <fileset dir="assembly/docfiles">
                                                <include name="img/**" />
                                                <include name="*.js" />
                                            </fileset>
                                        </copy>

                                            <taskdef name="doctask" classname="org.apache.ignite.tools.ant.beautifier.GridJavadocAntTask" />

                                            <doctask css="dotted" dir="target/javadoc/core">
                                                <include name="**/*.html" />
                                                <exclude name="overview-frame.html" />
                                                <exclude name="allclasses-frame.html" />
                                                <exclude name="**/class-use/*" />
                                            </doctask>
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>lgpl</id>
            <modules>
                <module>modules/schedule</module>
            </modules>
        </profile>

        <profile>
            <id>licenses</id>
            <build>
                <plugins>
                    <plugin><!-- skipping generation of dependencies licenses
                     to keep clean /maven-shared-archive-resources/META-INF
                     to prevent license.txt moving to sources.zip -->
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-remote-resources-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>ignite-dependencies</id>
                                <goals>
                                    <goal>process</goal>
                                </goals>
                                <configuration>
                                    <skip>true</skip>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>release</id>
            <build>
                <plugins>
                     <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <inherited>false</inherited>
                        <dependencies>
                            <dependency>
                                <groupId>${project.groupId}</groupId>
                                <artifactId>ignite-tools</artifactId>
                                <version>${project.version}</version>
                            </dependency>
                        </dependencies>
                        <executions>
                            <execution>
                                <id>release-postprocessing</id>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <phase>initialize</phase>
                                <configuration>
                                    <target>
                                        <replaceregexp byline="true">
                                            <regexp pattern="pushd &quot;%~dp0&quot;/\.\./\.\.(\s*&amp;::.+)?" />
                                            <substitution expression="pushd &quot;%~dp0&quot;/.." />
                                            <fileset dir="${basedir}/target/release-package-${ignite.edition}/bin">
                                                <include name="**/*.bat" />
                                            </fileset>
                                        </replaceregexp>

                                        <replaceregexp byline="true">
                                            <regexp pattern="IGNITE_HOME_TMP=&quot;\$\(dirname &quot;\$\{IGNITE_HOME_TMP\}&quot;\)&quot;(\s*#.*)?" />
                                            <substitution expression="" />
                                            <fileset dir="${basedir}/target/release-package-${ignite.edition}/bin">
                                                <include name="**/*.sh" />
                                            </fileset>
                                        </replaceregexp>

                                        <replaceregexp byline="true">
                                            <regexp pattern="set SCRIPTS_HOME=%IGNITE_HOME%\\bin(\s*&amp;::.*)?" />
                                            <substitution expression="set SCRIPTS_HOME=%IGNITE_HOME%\\\\bin" />
                                            <fileset dir="${basedir}/target/release-package-${ignite.edition}/bin">
                                                <include name="**/*.bat" />
                                            </fileset>
                                        </replaceregexp>

                                        <replaceregexp byline="true">
                                            <regexp pattern="SCRIPTS_HOME=&quot;\$\{IGNITE_HOME_TMP\}/bin&quot;(\s*#.*)?" />
                                            <substitution expression="SCRIPTS_HOME=&quot;$${IGNITE_HOME_TMP}/bin&quot;" />
                                            <fileset dir="${basedir}/target/release-package-${ignite.edition}/bin">
                                                <include name="**/*.sh" />
                                            </fileset>
                                        </replaceregexp>

                                        <replaceregexp byline="true">
                                            <regexp pattern="\. &quot;\$\{SCRIPTS_HOME\}&quot;/include/build-classpath.sh(\s*#.*)?" />
                                            <substitution expression="" />
                                            <fileset dir="${basedir}/target/release-package-${ignite.edition}/bin">
                                                <include name="**/*.sh" />
                                            </fileset>
                                        </replaceregexp>

                                        <replaceregexp byline="true">
                                            <regexp pattern="call &quot;%SCRIPTS_HOME%\\include\\build-classpath.bat&quot;(\s*&amp;::.*)?" />
                                            <substitution expression="" />
                                            <fileset dir="${basedir}/target/release-package-${ignite.edition}/bin">
                                                <include name="**/*.bat" />
                                            </fileset>
                                        </replaceregexp>

                                        <replaceregexp byline="true">
                                            <regexp pattern="ENABLE_ASSERTIONS=.*" />
                                            <substitution expression="ENABLE_ASSERTIONS=&quot;0&quot;" />
                                            <fileset dir="${basedir}/target/release-package-${ignite.edition}/bin">
                                                <include name="**/*.sh" />
                                            </fileset>
                                        </replaceregexp>

                                        <replaceregexp byline="true">
                                            <regexp pattern="ENABLE_ASSERTIONS=.*" />
                                            <substitution expression="ENABLE_ASSERTIONS=0" />
                                            <fileset dir="${basedir}/target/release-package-${ignite.edition}/bin">
                                                <include name="**/*.bat" />
                                            </fileset>
                                        </replaceregexp>

                                        <replaceregexp byline="true">
                                            <regexp pattern="-DIGNITE_UPDATE_NOTIFIER=false" />
                                            <substitution expression="" />
                                            <fileset dir="${basedir}/target/release-package-${ignite.edition}/bin">
                                                <include name="**/*.sh" />
                                                <include name="**/*.bat" />
                                            </fileset>
                                        </replaceregexp>

                                        <replaceregexp file="${basedir}/target/release-package-${ignite.edition}/examples/pom.xml" byline="true">
                                            <regexp pattern="to_be_replaced_by_ignite_version" />
                                            <substitution expression="${project.version}" />
                                        </replaceregexp>

                                        <replaceregexp file="${basedir}/target/release-package-${ignite.edition}/benchmarks/sources/pom.xml" byline="true">
                                            <regexp pattern="to_be_replaced_by_ignite_version" />
                                            <substitution expression="${project.version}" />
                                        </replaceregexp>

                                        <chmod dir="${basedir}/target/release-package-${ignite.edition}" perm="755" includes="**/*.sh" />

                                        <!--
                                        Line ending bugfix for builds packaged in MS Windows machine to adjust Linux based
                                        end-of-line characters for Linux shell scripts
                                        -->
                                        <fixcrlf srcdir="${basedir}/target/release-package-${ignite.edition}" eol="lf" eof="remove">
                                            <include name="**/*.sh" />
                                        </fixcrlf>

                                        <zip destfile="${basedir}/target/bin/${ignite.edition}-${project.version}-bin.zip" encoding="UTF-8">
                                            <zipfileset dir="${basedir}/target/release-package-${ignite.edition}" prefix="${ignite.edition}-${project.version}-bin" filemode="755">
                                                <include name="**/*.sh" />
                                                <include name="**/configure" />
                                                <include name="**/install-sh" />
                                                <include name="**/compile" />
                                                <include name="**/missing" />
                                            </zipfileset>
                                            <zipfileset dir="${basedir}/target/release-package-${ignite.edition}" prefix="${ignite.edition}-${project.version}-bin">
                                                <exclude name="**/*.sh" />
                                                <exclude name="**/configure" />
                                                <exclude name="**/install-sh" />
                                                <exclude name="**/compile" />
                                                <exclude name="**/missing" />
                                            </zipfileset>
                                        </zip>
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <version>2.4</version>
                        <inherited>false</inherited>
                        <executions>
                            <execution>
                                <id>ignite-dependencies</id>
                                <phase>validate</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                                <configuration>
                                    <descriptors>
                                        <descriptor>${basedir}/assembly/dependencies-${ignite.edition}.xml</descriptor>
                                    </descriptors>
                                    <outputDirectory>${basedir}/target/release-package-${ignite.edition}</outputDirectory>
                                    <finalName>libs</finalName>
                                    <appendAssemblyId>false</appendAssemblyId>
                                </configuration>
                            </execution>

                            <execution>
                                <id>ignite-release</id>
                                <phase>validate</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                                <configuration>
                                    <descriptors>
                                        <descriptor>assembly/release-${ignite.edition}.xml</descriptor>
                                    </descriptors>
                                    <finalName>release-package-${ignite.edition}</finalName>
                                    <appendAssemblyId>false</appendAssemblyId>
                                </configuration>
                            </execution>

                            <execution>
                                <id>dependencies-sqlline</id>
                                <phase>validate</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                                <configuration>
                                    <descriptors>
                                        <descriptor>assembly/dependencies-sqlline.xml</descriptor>
                                    </descriptors>
                                    <outputDirectory>target/release-package-${ignite.edition}</outputDirectory>
                                    <finalName>bin</finalName>
                                    <appendAssemblyId>false</appendAssemblyId>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-deploy-plugin</artifactId>
                        <configuration>
                            <skip>true</skip>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>yardstick</id>
            <modules>
                <module>modules/yardstick</module>
            </modules>
        </profile>

        <profile>
            <id>benchmarks</id>
            <modules>
                <module>modules/benchmarks</module>
            </modules>
        </profile>

        <profile>
            <id>examples</id>
            <modules>
                <module>examples</module>
            </modules>
        </profile>

        <profile>
            <id>update-versions</id>
            <!-- updates versions -->
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>update-versions</id>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <phase>validate</phase>
                                <configuration>
                                    <target>
                                        <echo message="Update ignite.version in docs" />

                                        <replaceregexp byline="true" encoding="UTF-8">
                                            <regexp pattern="(&lt;ignite\.version&gt;).+(&lt;/ignite\.version&gt;)" />
                                            <substitution expression="\1${project.version}\2" />
                                            <fileset dir="${project.basedir}/docs/">
                                                <include name="_docs/code-snippets/java/pom.xml" />
                                            </fileset>
                                        </replaceregexp>

                                        <replaceregexp byline="true" encoding="UTF-8">
                                            <regexp pattern="(version: ).+" />
                                            <substitution expression="\1${project.version}" />
                                            <fileset dir="${project.basedir}/docs/">
                                                <include name="_config.yml" />
                                            </fileset>
                                        </replaceregexp>

                                        <echo message="Update ignite.version in ducktests" />

                                        <replaceregexp byline="true" encoding="UTF-8">
                                            <regexp pattern="(__version__ = ).*$"/>
                                            <substitution expression="\1'${project.version}'" />
                                            <fileset dir="${project.basedir}/modules/ducktests/">
                                                <include name="tests/ignitetest/__init__.py" />
                                            </fileset>
                                        </replaceregexp>

                                        <echo message="Update ignite.version in C++" />

                                        <replaceregexp byline="true" encoding="UTF-8">
                                            <regexp pattern="(project\(.*\s)\d+\.\d+\.\d+.*?(\))" />
                                            <substitution expression="\1${ignite.platform.full.version}\2" />
                                            <fileset dir="${project.basedir}/modules/platforms/cpp/">
                                                <include name="**/CMakeLists.txt" />
                                            </fileset>
                                        </replaceregexp>

                                        <echo message="Update ignite.version in .NET" />

                                        <replaceregexp byline="true" encoding="UTF-8">
                                            <regexp pattern="(\[assembly:\s*Assembly\w*Version\w*\(&quot;)\d+\.\d+\.\d+(\.\d+)?(&quot;\)\])" />
                                            <substitution expression="\1${ignite.platform.full.version}\3" />
                                            <fileset dir="${project.basedir}/modules/platforms/dotnet/">
                                                <include name="**/SharedAssemblyInfo.cs" />
                                            </fileset>
                                        </replaceregexp>

                                        <replaceregexp byline="true" encoding="UTF-8">
                                            <regexp pattern="(\[assembly:\s*AssemblyInformationalVersion\w*\(&quot;).*?(&quot;\)\])" />
                                            <substitution
                                                expression="\1${ignite.majorVersion}.${ignite.minorVersion}.${ignite.incrementalVersion}\2" />
                                            <fileset dir="${project.basedir}/modules/platforms/dotnet/">
                                                <include name="**/SharedAssemblyInfo.cs" />
                                            </fileset>
                                        </replaceregexp>

                                        <echo message="Update ignite.version in resource files" />

                                        <replaceregexp byline="true" encoding="UTF-8">
                                            <regexp pattern="(ignite.version=).+$" />
                                            <substitution expression="\1${project.version}" />
                                            <fileset dir="${project.basedir}/modules/core/">
                                                <include name="src/main/resources/ignite.properties" />
                                            </fileset>
                                        </replaceregexp>

                                        <echo message="Update ignite.version in build.gradle" />

                                        <replaceregexp byline="true" encoding="UTF-8">
                                            <regexp pattern="(ignVer = ).*$"/>
                                            <substitution expression="\1'${project.version}'" />
                                            <fileset dir="${project.basedir}/modules/dev-utils/">
                                                <include name="ignite-modules-test/build.gradle" />
                                            </fileset>
                                        </replaceregexp>
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <!--
            This profile is used to provide a check that all tests are defined in at least one suite.

            Some Ignite tests can be declared within one maven module but ran in a suite declared in a different module.
            Then it's impossible to create an isolated check for every module. We should aggregate info from all modules
            and make a final decision on the aggregation result.

            The maven project apache-ignite:pom is the last that is built for the maven reactor.
            We leverage on that and provide clean and assertion tasks here.
            -->
            <id>check-test-suites</id>

            <build>
                <plugins>
                    <plugin>
                        <!-- Clean up custom surefire test provider. -->
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <delete>
                                            <fileset dir="${basedir}/modules/tools/target/classes/META-INF/services" />
                                        </delete>
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <!-- Check final list of orphaned tests. -->
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>test</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <includePluginDependencies>true</includePluginDependencies>
                            <mainClass>org.apache.ignite.tools.surefire.testsuites.AssertOnOrphanedTests</mainClass>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>clean</phase>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                        <configuration>
                            <filesets>
                                <fileset>
                                    <directory>libs</directory>
                                </fileset>
                            </filesets>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
